<?php
/**
 * Created by PhpStorm
 * User: 龍zero
 * Date: 2022-04-10
 * Time: 16:28
 */
declare(strict_types=1);

namespace App\Request\Users;

use Hyperf\Validation\Request\FormRequest;

class ChangePasswordRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     */
    public function authorize(): bool
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     */
    public function rules(): array
    {
        return [
            'new_password' => 'required|regex:/^[A-Za-z0-9_*&$#@]{6,22}$/|confirmed:confirm_password',
            'confirm_password' => 'required',
            'old_password' => 'required',
        ];
    }
    /**
     * 获取已定义验证规则的错误消息
     */
    public function messages(): array
    {
        return [
            'new_password.required' => '请输入新密码',
            'new_password.regex' => '新密码格式必须遵循密码规则且在6-22个字符之间',
            'new_password.confirmed' =>'两次密码输入不一致',
            'confirm_password.required'  => '请重复输入新密码',
            'old_password.required'  => '请输入旧密码验证',
        ];
    }
}
